package com.bkgy.modular.rawMaterialRules.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bkgy.modular.rawMaterialRules.entity.AcidRollingStock;
import com.bkgy.modular.rawMaterialRules.mapper.AcidRollingStockMapper;
import com.bkgy.modular.rawMaterialRules.service.AcidRollingStockService;
import com.bkgy.sys.common.entity.ResultData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ZhuHongKai
 * @version 1.0
 * @ClassName AcidRollingStockServiceImpl
 * @date 2023/1/4 16:06
 */
@Service
public class AcidRollingStockServiceImpl extends ServiceImpl<AcidRollingStockMapper, AcidRollingStock> implements AcidRollingStockService {
    @Resource
    private AcidRollingStockMapper acidRollingStockMapper;

    /**
     * 酸轧原料审核硅钢阈值配置查询数据
     * @return
     */
    @Override
    public ResultData findAcidRollingStockData() {
        List<AcidRollingStock> list = acidRollingStockMapper.selectList(null);
        return ResultData.ResultDataFaultSelf("查询成功",list);
    }

    /**
     * 酸轧原料审核硅钢阈值配置更新数据
     * @param jsonObject
     * @return
     */
    @Override
    public ResultData updateAcidRollingStockData(JSONObject jsonObject) {
        try {
            String dataId = jsonObject.getString("dataId");
            LambdaQueryWrapper<AcidRollingStock> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(AcidRollingStock::getGrade1,dataId);
            String data = jsonObject.getJSONObject("data").toJSONString();
            AcidRollingStock AcidRollingStock = JSON.parseObject(data,AcidRollingStock.class);
            acidRollingStockMapper.update(AcidRollingStock,queryWrapper);
            return ResultData.ResultDataSuccessSelf("修改成功", null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("修改失败，错误信息为" + e.getMessage(), null);
        }
    }
}
